package com.yixuan.mt.common.mapper;

import com.yixuan.mt.common.entity.Objects;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ObjectsMapper {

    @Insert("insert into objects (name, type, size, last_modified_time, parent) values (#{name}, #{type}, #{size}, #{lastModifiedTime}, #{parentPath})")
    void insertObject(Objects objects);

    void insertObjects(List<Objects> objects);

    @Update("update buckets set object_num = object_num + 1 where name = #{bucketName}")
    void updateAddObjectNum(String bucketName);

    @Update("update buckets set object_num = object_num - #{num} where name = #{bucketName}")
    void updateReduceObjectNum(String bucketName, int num);

    void deleteObjects(List<Integer> ids);

    @Select("select * from objects where id > #{lastId} and parent = #{parentPath} limit 20")
    List<Objects> selectObjects(Integer lastId, String parentPath);

    @Select("select count(*) from objects where name = #{objectName} and parent = #{parent}")
    boolean selectIsObjectExist(String objectName, String parent);
}
